<?php
session_start(); 
include("include/db.php");

$msg="";

$user_name	=	$_COOKIE["admin_uname"];
$pass		=	$_COOKIE["admin_pwd"];
$auto_login =	$_COOKIE["admin_auto_login"];


if(isset($_REQUEST['action']) and $_REQUEST['action'] == "login"){

	$usr_name = $_REQUEST['usr_name'];
	$usr_pwd = $_REQUEST['usr_pwd'];
	
	$q	=	"SELECT admin_id,admin_name,admin_password FROM software_admin 
								WHERE `admin_name` = '$usr_name' AND `admin_password` = '".$usr_pwd."' AND active = 'Y'";
	$rs	=	mysql_query($q);
	
	if(mysql_num_rows($rs) == 1)
	{
		$row 							=	mysql_fetch_array($rs);
		$_SESSION['admin_user_name']	=	$usr_name;
		$_SESSION['admin_user_id']		=	$row['admin_id'];
	
		if($_REQUEST['auto']=="1"){
			
			setcookie("admin_uname",$usr_name, time()+7*24*3600);
			setcookie("admin_pwd",$usr_pwd, time()+7*24*3600);
			setcookie("admin_auto_login",$_REQUEST['auto'], time()+7*24*3600);
	
		}
		
		if($_REQUEST['auto']==""){
	
			$usr_name	=	"";
			$usr_pwd	=	"";
			
			$_REQUEST['auto']="";
			setcookie("admin_uname",$usr_name, time()+7*24*3600);
			setcookie("admin_pwd",$usr_pwd, time()+7*24*3600);
			setcookie("admin_auto_login",$_REQUEST['auto'], time()+7*24*3600);
		}	
		
		header("location:main.php");
	}else
	{
		$msg="Invalid UserName/Password. Please Try Again.";
	} 
}
 ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?=TITLE_WEBSITE?></title>
<link href="css/c_energy.css" rel="stylesheet" type="text/css" />
<script src="include/AjaxQuery.js" type="text/javascript"></script>
<style type="text/css">
<!--
.style4 {
	font-size: 22px;
	font-weight: bold;
}
.style6 {color: #999999}
-->
</style>
</head>

<body bgcolor="#fafafa">
    
<table width="100%" align="center" cellpadding="0" cellspacing="0" >
<tr>
    <td align="center"><?  include("header.php"); ?></td>
  </tr>
  <tr>

    <td align="center" ><table width="100%" cellspacing="0" cellpadding="0">
  
      <tr bgcolor="#FAFAFA">
        <td colspan="2" align="left" valign="top" style="padding-left:15px; padding-top:150px">
		
		
		  <table width="100%"  cellspacing="0" cellpadding="0">
		    <tr>
		      <td align="center"  bgcolor="#FAFAFA">
			  
			  
			  			<form name="signform" action="" method="post" id="signform" >
			<table id="signInTbl" align="center"  width="417" cellspacing="3" cellpadding="0" style="border:solid #cccccc 1px">
		          <tr>
		            <td width="251" colspan="2" align="left" bgcolor="#373737" class="loc_search_found_term"  style="border-bottom:solid #cccccc 1px">&nbsp;Admin Login</td>
                </tr>
		          <tr>
		            <td width="251" colspan="2"><div align="center" class="ErrorMsg" id="err_signin" style="display:block"><?=$msg?></div></td>
                </tr>
		          <tr>
		            <td width="73" align="left">User Name </td>
                  <td width="163" align="left"><input name="usr_name" id="usr_name" type="text" class="Box" value="<?=$user_name?>" /></td>
                </tr>
		          <tr>
		            <td align="left">Password</td>
                  <td align="left"><input name="usr_pwd" id="usr_pwd" type="password" class="Box" value="<?=$pass?>" /></td>
                </tr>
		          <tr>
		            <td align="left">Remember</td>
                  <td align="left"><input name="auto" type="checkbox" id="auto"  value="1" <?=($auto_login=="1"?"checked":"")?> /></td>
                </tr>
		          <tr style="background: #CCC">
		          
                  <td height="20" colspan="2" align="center" valign="bottom"><input name="action" type="hidden" value="login" />
                    <input name="Submit" type="submit" style="background-color:#373737; color:#FFFFFF; border:none; font-weight:bold; width:100px" value="Sign In" />                </td>
                </tr>
		          </table>
			  </form>	
			  
			  		  
			  
			  
			  </td>
            </tr>
	        </table></td>
        </tr>
     
    </table>
	
	<tr>
	<td>
	</td>
	</tr>
	
	</td>
  </tr>
</table>
</body>
</html>
